-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: workflow to upload theme directory artifact #39
Conversation
36f1f78
to
0a9c588
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Rise, this is awesome! 🎉
I think we're almost there...you're successfully building and pushing the docker image, but our production image will need to be built slightly different than our development image.
In our development image, we build all of the WordPress core files into the image, but then we mount our theme and configuration files as volumes when starting the development container via docker compose
. This is great for development, because instead of building our source code into the docker image, we can tell the container to read these files from our local disk, meaning that any changes to theme/configuration files do not require a rebuild of the docker image and restart of the container.
However, in our production image, we want to build all of our final template and configuration files into the image itself, so that all of that code is bundled with the image, and it can essentially run self-contained without the need to mount external volumes.
In order to do that, I think we can leverage multi-stage docker builds.
This will involve modifying Dockerfile
and docker-compose.yml
. Essentially, we'll use our existing steps in our Dockerfile
as the first stage of the build, called dev
, and then copy our build files into the image in a second stage, called prod
.
Updates to Dockerfile
At the top of Dockerfile
, we'll add as dev
as the build stage name:
FROM php:8.1-apache-buster as dev
This tells docker that all of the subsequent steps are part of the dev
stage. Then, at the bottom of the Dockerfile, we can specify a new stage called prod
, which uses dev
as a base:
FROM dev as prod
After that, we need to add some COPY
steps as part of this stage to copy over relevant files into the prod image. For example, to copy the theme files:
COPY theme /var/www/html/wp-content/themes/sparkpress
We can look at the volumes mounted in docker-compose.yml to see which files / folders we need to copy over. I think we'll need corresponding COPY
lines for each of these:
- theme
- wp-configs/wp-config.php
- wp-configs/php.ini
- wp-configs/.htaccess.
Updates to docker-compose.yml
Our docker-compose.yml
configuration is currently only used for local development. We can update the build
settings so that it only builds the dev
stage as a target:
build:
context: .
target: dev
The result is that:
- Our development environment runs the same, because it uses
docker-compose
and only builds thedev
part of the image. - Our production build, using
docker build .
runs both stages of the build, copying the necessary files into the final image that is pushed to Github.
Validation
We can validate this by verifying that:
- restarting the development environment doesn't break anything
- Running
docker build . --tag ghcr.io/sparkbox/sparkpress:latest
locally copies the production files into the image (requires runningnpm run build:prod
first) - We can run a container from the production image locally (I will follow up with more details here)
.github/workflows/deploy.yml
Outdated
username: ${{github.actor}} | ||
password: ${{secrets.GH_TOKEN}} | ||
|
||
- name: 'Build Inventory Image' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool, thanks for figuring this out!
.github/workflows/deploy.yml
Outdated
with: | ||
registry: ghcr.io | ||
username: ${{github.actor}} | ||
password: ${{secrets.GH_TOKEN}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this currently using a personal access token that you created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
f8d8fba
to
3189e6d
Compare
@rise-erpelding let's remove the multistage build and try copying the files directly into the image. We can remove the @robtarr after our discussion, I thought of one potential issue with this approach. We're using Edit |
I was able to successfully run the image as a container and run WordPress locally!
With these steps, I was able to run a container, connect to the database, log into the admin and upload a file to the mounted |
@jonoliver I have not been able to follow these instructions to run the container from the image with the database working--I keep getting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rise-erpelding apologies for the delay, following up here. There are a few more updates that I think we should make, then this should be ready to merge.
- Rename the action to
deploy.docker.yml
to match the format ofdeploy.pantheon.yml
- Add the
workflow_dispatch
to the action (example here) - Add
DEPLOY_WITH_DOCKER
conditional flag
To answer your questions:
Is this something that needs to be addressed? And if not, would the next step be to run the GitHub action again before merging and confirm that it seems to be doing the right things?
After we make the updates, we can pair to test this via workflow_dispatch
to ensure test the deployed image.
Also, we will ultimately need some documentation around this process, but I will create a new issue for that.
3c33f69
to
8c6ab93
Compare
@jonoliver I ran the workflow, saw a warning about using a deprecated version of node, updated the |
@rise-erpelding I tested the image created by the workflow, and was able to successfully run it locally! Here are the updated instructions I used to test. I don't think you need to walk through these steps before merging, but I'm capturing here in case we include any of these steps in a subsequent documentation PR.
|
28f9721
to
560ed30
Compare
|
||
jobs: | ||
deploy: | ||
if: ${{ vars.DEPLOY_WITH_DOCKER }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note in #94 that this is a variable that needs to be set in GitHub
with: | ||
registry: ghcr.io | ||
username: ${{github.actor}} | ||
password: ${{secrets.GH_TOKEN}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note in #94 that this is a secret that needs to be set in GitHub
560ed30
to
45c98d7
Compare
Description
This adds a GitHub Actions workflow that builds a Docker image using the repo's existing Dockerfile
Closes #21
To Validate
sha256
on the package taggedlatest
should match the one at the bottom of the "Build Inventory Image" step of the workflow). Optionally, you can also push a commit to run the workflow on PR and check it from there.Note: You should also be able to pull/run the image but it's kind of a hassle! You'd need to authenticate to the container registry. To run it locally I modified the
docker-compose.yml
as seen below and randocker-compose up
.